package com.millstein.tsinglog.model.pojo;

import lombok.Data;
import tk.mybatis.mapper.annotation.KeySql;

import javax.persistence.Id;
import javax.persistence.Table;

@Table(name = "sys_permission")
@Data
public class Permission implements Comparable<Permission> {

    @Id
    @KeySql(useGeneratedKeys = true)
    private Long id; // 主键
    private String permissionName; // 权限名称
    private Short permissionType; // 权限类型，1菜单，2按钮，3api
    private String permissionCode; // 权限代码
    private Long parentId; // 父id
    private Integer sort; // 排序
    private String url; // 地址
    private String icon; // 图标
    private Short status; // 状态
    private String createTime; // 创建时间
    private String updateTime; // 最后更新时间

    @Override
    public int compareTo(Permission old) {

        // 1.按照parentId排序
        if (this.parentId > old.getParentId()) {
            return (int) (this.parentId - old.getParentId());
        }
        if (this.parentId < old.getParentId()) {
            return (int) (this.parentId - old.getParentId());
        }

        // 2.按照sort排序
        if (this.sort.compareTo(old.getSort()) > 0) {
            return 1;
        }
        if (this.sort.compareTo(old.getSort()) < 0) {
            return -1;
        }

        return 0;
    }
}
